export const getRandomItem = (arr) => {
  return arr[Math.floor(Math.random() * arr.length)]
}
//从数组中随机获取制定长度的数据
export const getRandomFixedLengthArray = (arr, arrLength) => {
  return arr.reduce((t, i) => {
    console.log('__', i)
    if (t.length >= arrLength) {
      return t
    }
    const randomIt = getRandomItem(arr)
    const exists = t.some((n) => {
      return n.des === randomIt.des
    })

    if (!exists) {
      t.push(randomIt)
    }
    return t
  }, [])
}

// 返回数组A和数组B的差集 A多，B少
export const getDifferArrayRandomItem = (arr1, arr2) => {
  const newArr1 = arr1.reduce((a, b) => {
    if (a) {
      a.push(b?.name)
    }
    console.log('a', a)
    return a
  }, [])
  const newArr2 = arr2.reduce((a, b) => {
    if (a) {
      a.push(b?.name)
    }
    console.log('a', a)
    return a
  }, [])
  console.log('newArr1', newArr1, newArr2)
  const chaRandomItem = getRandomItem(
    newArr1.reduce((a, b) => {
      if (!newArr2.includes(b)) {
        a.push(b)
      }
      return a
    }, [])
  )
  console.log('sssss', chaRandomItem)
  return arr1.filter((e) => e.name == chaRandomItem)[0]
}
